﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
namespace LoginModule.CongCu
{
    /// <summary>
    /// Lop nay cap ma so cac don vi
    /// </summary>
    public static class CapMaSo
    {
        private static AccountModuleDataContext dbAccountModuleID = new AccountModuleDataContext();

        /// <summary>
        /// Cap ma so cho cac don vi dang ky thanh lap
        /// </summary>
        /// <param name="tinhThanh"></param>
        /// <param name="capDonVi"></param>
        /// <returns></returns>
        public static long capMaSoDangKyDonVi(int tinhThanh, int capDonVi)
        {
            string MaSo = "0";
            long id;
            string tmpTam;

            dbAccountModuleID.SP_LAY_MAX_MASODANGKY(tinhThanh, capDonVi, ref MaSo);
            
            if (MaSo != "0")
            {
                id = long.Parse(MaSo);
                id = id + 1;

            }
            else
            {
                tmpTam = tinhThanh.ToString() + capDonVi.ToString() + "0001";
                id = int.Parse(tmpTam);
            }

            return id;
        }
        /// <summary>
        /// Cap ma so don vi nganh
        /// </summary>
        /// <param name="idCap1"></param>
        /// <param name="nganh"></param>
        /// <returns></returns>
        public static long capMaSoDonViNganh(int tinhthanh, int nganh,int cap)
        {
            string maSoTam = "0";
            Int32 maInt=0;
            dbAccountModuleID.SP_LAY_MAX_MASODONVINGANH(tinhthanh, nganh,cap, ref maSoTam);

            if (!maSoTam.Equals("0"))
            {
                 maInt= Convert.ToInt32(maSoTam);
                maInt = maInt + 1;
            }
            else
            {
                string tam = tinhthanh.ToString() + nganh.ToString() + cap.ToString() + "0001";
                maInt = Convert.ToInt32(tam);
            }

            return maInt;
        }
        
    }
}
